#include "TreeNode.h"

namespace cppflib
{

namespace collections
{

namespace tree
{

TreeNode::TreeNode(void)
{
   this->m_pParent = NULL;
   this->m_leftChild = NULL;
   this->m_rightChild = NULL;
}

TreeNode::~TreeNode(void)
{
   this->m_pParent = NULL;
   this->m_leftChild = NULL;
   this->m_rightChild = NULL;
}

TreeNode * TreeNode::GetParent()
{
   return this->m_pParent;
}

TreeNode * TreeNode::GetLeftChild()
{
   return this->m_leftChild;
}

TreeNode * TreeNode::GetRightChild()
{
   return this->m_rightChild;
}

int TreeNode::GetChildNum()
{
   int nrChild = 0;
   if (this->m_leftChild) ++nrChild;
   if (this->m_rightChild) ++nrChild;
   return nrChild;
}

bool TreeNode::HasNoParent()
{
   return (this->m_pParent == NULL);
}

/**
 *  Get the depth of this node
 *  Root node is of depth zero.
 */
int TreeNode::GetDepth()
{
   int depth = 0;
   TreeNode *pParent = this->m_pParent;
   while (pParent) {
      ++depth;
      pParent = pParent->m_pParent;
   }
   
   return depth;
}


}  // end of namespace tree

}  // end of namespace collections

}  // end of namespace cppflib

